#ifndef _D96F494C_DC48_4B8C_A078_346504A09C9C
#define _D96F494C_DC48_4B8C_A078_346504A09C9C

namespace std
{
	/**
	* @brief        一个能保证插入顺序和读取顺序一致的容器
	* @author       xktesla
	*/
	template<typename _Kty, typename _Ty, class _Alloc = allocator<_Ty>>
	class maplist : public list<pair<_Kty, _Ty>>
	{
	public:
		using list<pair<_Kty, _Ty>>::list;

		typedef list<pair<_Kty, _Ty>> _Mybase;
		typedef typename _Mybase::iterator iterator;

		void erase(const _Kty& k)
		{
			auto itFind = find_if(_Mybase::begin(), _Mybase::end(), [&](const pair<_Kty, _Ty>& it)->bool {return(it.first == k); });
			if (itFind != _Mybase::end()) { _Mybase::erase(itFind); }
		}
		void erase(const iterator& it)
		{
			_Mybase::erase(it);
		}
		iterator find(const _Kty& k)
		{
			return find_if(_Mybase::begin(), _Mybase::end(), [&](const pair<_Kty, _Ty>& it)->bool {return(it.first == k);});
		}
		_Ty& operator[](const _Kty& k)
		{
			auto itFind = find_if(_Mybase::begin(), _Mybase::end(), [&](const pair<_Kty, _Ty>& it)->bool {return (it.first == k);});
			if (itFind == _Mybase::end())
			{
				itFind = _Mybase::insert(_Mybase::end(), make_pair(k, _Ty()));
			}
			return itFind->second;
		}
	};
}

#endif
